home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / util / boot / RNDBackdrop.lha / RNDBackdrop / ScanPicDir < prev    next >
Text File  |  1995-08-08  |  3KB  |  115 lines

  1. /*  ScanPicDir - Scans for WB Backdrops and writes them in a file
  2. **
  3. **  By Reinhard Katzmann  suamor@student.uni-tuebingen.de
  4. **/
  5. version='$VER: ScanPicDir 1.0 (8.8.95)
  6. '
  7. SIGNAL ON BREAK_D
  8. SIGNAL ON BREAK_C
  9.  
  10. OPTIONS RESULTS
  11.  
  12. if ~show('L', 'rexxdossupport.library') then    /* Just for ReadArgs() */
  13.     call addlib('rexxdossupport.library',0,-30)
  14.  
  15. if ~show('L', 'rexxarplib.library') then        /* For FileList() */
  16.     call addlib('rexxarplib.library',0,-30)     /* and Getenv()   */
  17.  
  18. /* Parse arguments */
  19. /*  Usage: ScanPicDir Paths/M,Pattern/K,ALL/S,DIR/S,Outfile/K */
  20.  
  21. parse arg args
  22.  
  23. template = 'Paths/M,Pattern/K,ALL/S,DIRS/S,FILES/S,Outfile/K'
  24.  
  25. Paths.count=0
  26. Paths.0=''
  27. ALL=1
  28. DIRS=0
  29. FILES=0
  30. Outfile="sys:t/backdrops"
  31. Pattern='~(#?.info)'
  32. numfiles=0
  33.  
  34. if (args=='?') then do
  35.     writech(stdout,template': ')
  36.     parse pull moreargs
  37.     if (moreargs=='?') then do
  38.         say "ScanPicDir"
  39.         say "By Reinhard Katzmann  suamor@student.uni-tuebingen.de"
  40.         say version
  41.         say ""
  42.         say "Usage: ScanPicDir "template
  43.         say ""
  44.         say '       You do not need to put a "/" at the end of the Path.'
  45.         say "       You can give several dirs as arguments"
  46.         say ""
  47.         say "Example:"
  48.         say "    RX ScanPicDir sys:prefs/presets/backdrops"
  49.         say "        scans the dir and writes contents to sys:t/backdrops"
  50.         exit
  51.     end
  52.     else args=moreargs
  53. end
  54.  
  55. ReadArgs(args,template)
  56.  
  57. if Paths.count=0 then do
  58.     Paths.count=1
  59.     Paths.0=''
  60. end
  61.  
  62. SELECT                                              /* options for showdir() */
  63.     when ALL   then option=''
  64.     when DIRS  then option='D'
  65.     when FILES then option='F'
  66.     OTHERWISE option=''
  67. END
  68.  
  69. /* Main Program */
  70.  
  71. do i=0 to (Paths.count-1)
  72.     IF (~exists(Paths.i)) then do                             /* Can't find Path */
  73.         say "Can't find Path "Paths.i
  74.      exit
  75.     END
  76.  
  77.     if (Paths.i~='') then do
  78.         trim(Paths.i)                        /* Check for / or : at end of Path and add one*/
  79.         IF (right(Paths.i, 1) ~= '/')&(right(Paths.i,1)~=':') then do /* if not already there. */
  80.                 Paths.i = Paths.i'/'
  81.         END
  82.     end
  83.  
  84.     num = FileList(Paths.i''Pattern, afile, option, 'e') /* 'e' causes it to return */
  85.                                                          /* the full path           */
  86.     do loop=1 to num
  87.         numfiles=numfiles+1
  88.         thefile.numfiles=afile.loop
  89.     end
  90. end /* do loop */
  91.  
  92. if numfiles=0 then do
  93.   say "Error: Directory is empty"
  94.   exit
  95.   end
  96. else do
  97.   if (Open('fp',Outfile,'W')) then do until numfiles=0
  98.     name=thefile.numfiles
  99.     writeln('fp',name)
  100.     numfiles=numfiles-1
  101.   end
  102.   else do
  103.     say "Could not open Outfile" Outfile" for writing."
  104.     exit
  105.   end
  106. end
  107. Close('fp')
  108. say "File "Outfile" succesfully written"
  109.  
  110. BREAK_D:
  111. exit
  112.  
  113. BREAK_C:
  114. exit
  115.